import { MessageBoxService, GrowlMessageType } from './../../components/messageBox';
import { StoreSvr } from './../../services/store';
import { PrinterManager } from './../../utils/print/printer/printManager';
import { Component, Output, EventEmitter } from '@angular/core';
@Component({
    selector: 'wifi-print',
    template: `
        <div class="flex-column">
            <div class="title bg-darkgray" (click)="changeName('interfaceType')">
                <i class="material-icons icon">navigate_before</i>
                <span>设置网络打印机参数</span>
            </div>
            <div class="wifi-content">
                <div class='v-gap'>
                    <div class='caption-text margin-t-s'>设备的网络地址(IP)</div>
                    <input type='text' name='wifi' class='wifi-input margin-t-s' placeholder='输入IP/域名:端口' [(ngModel)]="host"/>
                    <div class='text-desc margin-t-s'>
                        请首先根据厂商的使用说明书，将网络打印机接入到网络中，并保证当前终端可以访问。端口地址不设置默认为9100。
                    </div>
                </div>
                <div class="btn-search-wifi margin-t-s" (click)="findDevice()">查找设备</div>
            </div>
        </div>
    `,
    styleUrls: ['./printer.component.scss']
})

export class WifiPrintComponent {
    @Output()
    changePageName: EventEmitter<any> = new EventEmitter<any>();

    constructor(
        private printerManager: PrinterManager,
        private storeSvr: StoreSvr

    ) { }

    private host: string;

    changeName(name) {
        this.changePageName.emit(name);
    }

    async findDevice() {
        if(!this.host){
            MessageBoxService.current.Growl(GrowlMessageType.Error, "错误提示", "请填写打印机网络地址");
            return false;
        }
        this.storeSvr.setHost(this.host);
        this.changeName('searchDevice');
    }
}